package gui;

import com.fitapp.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SportsArrayAdapter extends ArrayAdapter<String>{

    Context context;
    int layoutResourceId;   
    String data[] = null;
   
    public SportsArrayAdapter(Context context, int layoutResourceId, String[] data) 
    {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View row = convertView;
        RowHolder holder = null;
       
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
           
            holder = new RowHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
           
            row.setTag(holder);
        }
        else
        {
            holder = (RowHolder)row.getTag();
        }
       
        // Fill row entry with content
        String sport = data[position];
        holder.txtTitle.setText(sport);
       
        // Select according image
        if (sport.contains( "Jogging" ))
        {
        	holder.imgIcon.setImageResource(R.drawable.jogging);
        }
        else if (sport.contains( "Banding" ))
        {
        	holder.imgIcon.setImageResource(R.drawable.banding);
        }
        else if (sport.contains( "Press" ))
        {
        	holder.imgIcon.setImageResource(R.drawable.pressup);
        }
        else if (sport.contains( "Sit" ))
        {
        	holder.imgIcon.setImageResource(R.drawable.situp);
        }
        else
        {
        	holder.imgIcon.setImageResource(R.drawable.ic_launcher);
        }
       
        return row;
    }
   
    static class RowHolder
    {
        ImageView imgIcon;
        TextView txtTitle;
    }
}